package com.gameguru.mathgame;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.preference.PreferenceManager;
import android.widget.LinearLayout;


public class GameHelper extends Activity {
	private Context context;
	private SharedPreferences sharedPreferences;
	int color[] = {Color.BLACK,Color.WHITE,Color.BLUE,Color.GREEN,Color.YELLOW,Color.RED,Color.MAGENTA,Color.GRAY,Color.CYAN,Constants.DEFAULT};
	private int noOfQuestions = 0;

	public GameHelper(Context context) {	
		this.context = context;
		sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
		setNoOfQuestions();
	}
	public String getPlayerName() {
		return  sharedPreferences.getString(context.getString(R.string.player_name), Constants.GUEST);
	}
	/*public void setPlayerName(String playerName) {
		this.playerName = sharedPreferences.getString(context.getString(R.string.player_name), "Guest");
	}*/

	public LinearLayout bgSettings(LinearLayout layout) {
		try {
			
			String colorcode = sharedPreferences.getString(
					context.getString(R.string.color), (Constants.DEFAULT).toString());
			if( Integer.parseInt(colorcode)== Constants.DEFAULT) {
				layout.setBackgroundResource(R.drawable.blackboard);
			} else if (Integer.parseInt(colorcode)== Constants.DEFAULT_BOARD){
				layout.setBackgroundResource(R.drawable.big_blank_blackboard);
			} else {
				layout.setBackgroundColor(color[Integer.parseInt(colorcode)]);
			}


		} catch (Exception e) {
			e.printStackTrace();
		}
		return layout;

	}
	public int getNoOfQuestions() {
		return noOfQuestions;
	}
	public void setNoOfQuestions() {
		try {
			String noq = sharedPreferences.getString(
					context.getString(R.string.pref_Q_selection), Constants.DEFAULT_TOTAL_QUESTIONS_TEN.toString());
			this.noOfQuestions  = Integer.parseInt(noq);
			if (noOfQuestions<=0)
				noOfQuestions = Constants.DEFAULT_TOTAL_QUESTIONS_TEN;
		} catch (Exception e) {
			
			e.printStackTrace();
		}
		
	}


}
